<?php
declare (strict_types = 1);

namespace app\admin\controller;
use think\facade\View;
use think\facade\Request;
class News extends \app\admin\controller\Base
{
  
  public function upload()
  {
    // $r['url'] = 'https://cdn.novenn.com/random/images/2020-05-30.jpg';
    // return $this->doSuccess('ok',$r);
    $image = request()->file('file');
    try {
      validate(
        [
          'file' => 
          [
            'fileExt' => 'gif,jpg,png'
          ]
        ]
      )->check(['file' => $image]);
      
      $savename = \think\facade\Filesystem::putFile('', $image);
      $path = "./upload/".$savename;
      $url = Request::domain()."/upload/".$savename;
      $r['url'] = $url;
      return $this->doSuccess('ok',$r);
    } catch (\think\exception\ValidateException $e) {
      return $this->doError('ok',$e->getMessage());
    }
  }
}
